package com.xqboss.apps.service.punch;


import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xqboss.apps.domain.punch.PunchUserSlot;
import com.xqboss.apps.mapper.punch.PunchUserSlotMapper;

import java.util.List;


/**
 * 打卡-用户卡槽(PunchUserSlot)表服务实现类
 *
 * @author makejava
 * @since 2024-03-18 16:36:49
 */
@Service
public class PunchUserSlotService extends ServiceImpl<PunchUserSlotMapper, PunchUserSlot> {

    /**
     * 通过用户id查询用户所有卡槽
     */
    public List<PunchUserSlot> selectInByUserId(Long userId, List<Integer> status) {
        return this.lambdaQuery()
                .eq(PunchUserSlot::getUserId, userId)
                .in(!status.isEmpty(), PunchUserSlot::getStatus, status)
                .list();
    }

    /**
     * 通过用户id查询用户所有卡槽
     */
    public List<PunchUserSlot> selectByUserId(Long userId, Integer status) {
        return this.lambdaQuery()
                .eq(PunchUserSlot::getUserId, userId)
                .eq(status != null, PunchUserSlot::getStatus, status)
                .list();
    }

    /**
     * 通过用户id卡槽id查询用户卡槽是否存在
     *
     * @param userId 用户id
     *               id 卡槽id
     */
    public boolean checkSlotExist(Long userId, Long id) {
        return this.lambdaQuery()
                .eq(PunchUserSlot::getUserId, userId)
                .eq(PunchUserSlot::getSlotId, id)
                .count() > 0;
    }

    /**
     * 通过用户id卡槽id查询用户卡槽
     *
     * @param userId 用户id
     *               id 卡槽id
     */
    public PunchUserSlot selectSlotByUserIdAndSlotId(Long userId, Long slotId) {
        return this.lambdaQuery()
                .eq(PunchUserSlot::getUserId, userId)
                .eq(PunchUserSlot::getSlotId, slotId)
                .one();
    }

    /**
     * 根据用户id,卡槽id,更新卡槽状态
     * @param slotId
     * @param userId
     * @param status
     */
    public void updateStatus(Long userId, Long slotId, int status) {
        this.lambdaUpdate()
                .eq(PunchUserSlot::getUserId, userId)
                .eq(PunchUserSlot::getSlotId, slotId)
                .set(PunchUserSlot::getStatus, status)
                .update();
    }
}
